<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //全局匹配时，想要使用 index input groups属性的话，使用exec,原理是lastindex每次加1
        let name="cdtw.com";
        let reg=/\w/g;
        // console.log(reg.exec(name));
        // console.log(reg.lastIndex);//1
        // console.log(reg.exec(name));
        // console.log(reg.lastIndex);//2
        // console.log(reg.exec(name));
        // console.log(reg.lastIndex);//3
        // console.log(reg.exec(name));
        // console.log(reg.exec(name));
        // console.log(reg.exec(name));
        // console.log(reg.exec(name));
        
        // ['c', index: 0, input: 'cdtw.com', groups: undefined]
        // ['d', index: 1, input: 'cdtw.com', groups: undefined]
        // ['t', index: 2, input: 'cdtw.com', groups: undefined]
        // ['w', index: 3, input: 'cdtw.com', groups: undefined]
        // ['c', index: 5, input: 'cdtw.com', groups: undefined]
        // ['o', index: 6, input: 'cdtw.com', groups: undefined]
        // ['m', index: 7, input: 'cdtw.com', groups: undefined]
        while(res=reg.exec(name)){
            console.log(res);
        }
        // console.log(Boolean(null));//false
    </script>
</body>
</html>